import 'package:flutter_admin/utils/utils.dart';

class SaleOrder {
  String? id;
  String? campaignId;
  String? sourceId;
  String? mediumId;
  String? accessToken;
  String? messageMainAttachmentId;
  String? name;
  String? origin;
  String? clientOrderRef;
  String? reference;
  String? state;
  String? dateOrder;
  String? validityDate;
  String? requireSignature;
  String? requirePayment;
  String? createDate;
  String? createDateStart;
  String? createDateEnd;
  String? user;
  String? userName;
  String? partnerId;
  String? partnerName;
  String? partnerInvoiceId;
  String? partnerShippingId;
  String? pricelistId;
  String? currencyId;
  String? analyticAccountId;
  String? invoiceStatus;
  String? note;
  String? amountUntaxed;
  String? amountTax;
  String? amountTotal;
  String? currencyRate;
  String? paymentTermId;
  String? fiscalPositionId;
  String? companyId;
  String? companyName;
  String? teamId;
  String? signedBy;
  String? signedOn;
  String? commitmentDate;
  String? showUpdatePricelist;
  String? createUid;
  String? writeUid;
  String? writeDate;
  String? incoterm;
  String? pickingPolicy;
  String? warehouseId;
  String? procurementGroupId;
  String? effectiveDate;
  String? saleOrderTemplateId;
  String? placeorderdate;
  String? placeorderdateStart;
  String? placeorderdateEnd;
  String? verifydate;
  String? customercontractid;
  String? region;
  String? province;
  String? salesdepartment;
  String? deliverydate;
  String? iscp;
  String? deliveryproperties;
  String? remark;
  String? productName;
  String? spec;
  String? productQty;
  String? unit;
  String? customerName;
  String? autoid;

  SaleOrder({
    this.id,
    this.campaignId,
    this.sourceId,
    this.mediumId,
    this.accessToken,
    this.messageMainAttachmentId,
    this.name,
    this.origin,
    this.clientOrderRef,
    this.reference,
    this.state,
    this.dateOrder,
    this.validityDate,
    this.requireSignature,
    this.requirePayment,
    this.createDate,
    this.createDateStart,
    this.createDateEnd,
    this.user,
    this.userName,
    this.partnerId,
    this.partnerName,
    this.partnerInvoiceId,
    this.partnerShippingId,
    this.pricelistId,
    this.currencyId,
    this.analyticAccountId,
    this.invoiceStatus,
    this.note,
    this.amountUntaxed,
    this.amountTax,
    this.amountTotal,
    this.currencyRate,
    this.paymentTermId,
    this.fiscalPositionId,
    this.companyId,
    this.companyName,
    this.teamId,
    this.signedBy,
    this.signedOn,
    this.commitmentDate,
    this.showUpdatePricelist,
    this.createUid,
    this.writeUid,
    this.writeDate,
    this.incoterm,
    this.pickingPolicy,
    this.warehouseId,
    this.procurementGroupId,
    this.effectiveDate,
    this.saleOrderTemplateId,
    this.placeorderdate,
    this.placeorderdateStart,
    this.placeorderdateEnd,
    this.verifydate,
    this.customercontractid,
    this.region,
    this.province,
    this.salesdepartment,
    this.deliverydate,
    this.iscp,
    this.deliveryproperties,
    this.remark,
    this.productName,
    this.spec,
    this.productQty,
    this.unit,
    this.customerName,
    this.autoid,
  });

  SaleOrder copyWith({
    String? id,
    String? campaignId,
    String? sourceId,
    String? mediumId,
    String? accessToken,
    String? messageMainAttachmentId,
    String? name,
    String? origin,
    String? clientOrderRef,
    String? reference,
    String? state,
    String? dateOrder,
    String? validityDate,
    String? requireSignature,
    String? requirePayment,
    String? createDate,
    String? user,
    String? partnerId,
    String? partnerInvoiceId,
    String? partnerShippingId,
    String? pricelistId,
    String? currencyId,
    String? analyticAccountId,
    String? invoiceStatus,
    String? note,
    String? amountUntaxed,
    String? amountTax,
    String? amountTotal,
    String? currencyRate,
    String? paymentTermId,
    String? fiscalPositionId,
    String? companyId,
    String? teamId,
    String? signedBy,
    String? signedOn,
    String? commitmentDate,
    String? showUpdatePricelist,
    String? createUid,
    String? writeUid,
    String? writeDate,
    String? incoterm,
    String? pickingPolicy,
    String? warehouseId,
    String? procurementGroupId,
    String? effectiveDate,
    String? saleOrderTemplateId,
    String? placeorderdate,
    String? verifydate,
    String? customercontractid,
    String? region,
    String? province,
    String? salesdepartment,
    String? deliverydate,
    String? iscp,
    String? deliveryproperties,
    String? remark,
  }) {
    return new SaleOrder(
      id: id ?? this.id,
      campaignId: campaignId ?? this.campaignId,
      sourceId: sourceId ?? this.sourceId,
      mediumId: mediumId ?? this.mediumId,
      accessToken: accessToken ?? this.accessToken,
      messageMainAttachmentId:
          messageMainAttachmentId ?? this.messageMainAttachmentId,
      name: name ?? this.name,
      origin: origin ?? this.origin,
      clientOrderRef: clientOrderRef ?? this.clientOrderRef,
      reference: reference ?? this.reference,
      state: state ?? this.state,
      dateOrder: dateOrder ?? this.dateOrder,
      validityDate: validityDate ?? this.validityDate,
      requireSignature: requireSignature ?? this.requireSignature,
      requirePayment: requirePayment ?? this.requirePayment,
      createDate: createDate ?? this.createDate,
      user: user ?? this.user,
      partnerId: partnerId ?? this.partnerId,
      partnerInvoiceId: partnerInvoiceId ?? this.partnerInvoiceId,
      partnerShippingId: partnerShippingId ?? this.partnerShippingId,
      pricelistId: pricelistId ?? this.pricelistId,
      currencyId: currencyId ?? this.currencyId,
      analyticAccountId: analyticAccountId ?? this.analyticAccountId,
      invoiceStatus: invoiceStatus ?? this.invoiceStatus,
      note: note ?? this.note,
      amountUntaxed: amountUntaxed ?? this.amountUntaxed,
      amountTax: amountTax ?? this.amountTax,
      amountTotal: amountTotal ?? this.amountTotal,
      currencyRate: currencyRate ?? this.currencyRate,
      paymentTermId: paymentTermId ?? this.paymentTermId,
      fiscalPositionId: fiscalPositionId ?? this.fiscalPositionId,
      companyId: companyId ?? this.companyId,
      teamId: teamId ?? this.teamId,
      signedBy: signedBy ?? this.signedBy,
      signedOn: signedOn ?? this.signedOn,
      commitmentDate: commitmentDate ?? this.commitmentDate,
      showUpdatePricelist: showUpdatePricelist ?? this.showUpdatePricelist,
      createUid: createUid ?? this.createUid,
      writeUid: writeUid ?? this.writeUid,
      writeDate: writeDate ?? this.writeDate,
      incoterm: incoterm ?? this.incoterm,
      pickingPolicy: pickingPolicy ?? this.pickingPolicy,
      warehouseId: warehouseId ?? this.warehouseId,
      procurementGroupId: procurementGroupId ?? this.procurementGroupId,
      effectiveDate: effectiveDate ?? this.effectiveDate,
      saleOrderTemplateId: saleOrderTemplateId ?? this.saleOrderTemplateId,
      placeorderdate: placeorderdate ?? this.placeorderdate,
      verifydate: verifydate ?? this.verifydate,
      customercontractid: customercontractid ?? this.customercontractid,
      region: region ?? this.region,
      province: province ?? this.province,
      salesdepartment: salesdepartment ?? this.salesdepartment,
      deliverydate: deliverydate ?? this.deliverydate,
      iscp: iscp ?? this.iscp,
      deliveryproperties: deliveryproperties ?? this.deliveryproperties,
      remark: remark ?? this.remark,
    );
  }

  @override
  String toString() {
    return '''SaleOrder{
      id: id,
      campaignId: campaignId,
      sourceId: sourceId,
      mediumId: mediumId,
      accessToken: accessToken,
      messageMainAttachmentId: messageMainAttachmentId,
      name: name,
      origin: origin,
      clientOrderRef: clientOrderRef,
      reference: reference,
      state: state,
      dateOrder: dateOrder,
      validityDate: validityDate,
      requireSignature: requireSignature,
      requirePayment: requirePayment,
      createDate: createDate,
      user: user,
      partnerId: partnerId,
      partnerInvoiceId: partnerInvoiceId,
      partnerShippingId: partnerShippingId,
      pricelistId: pricelistId,
      currencyId: currencyId,
      analyticAccountId: analyticAccountId,
      invoiceStatus: invoiceStatus,
      note: note,
      amountUntaxed: amountUntaxed,
      amountTax: amountTax,
      amountTotal: amountTotal,
      currencyRate: currencyRate,
      paymentTermId: paymentTermId,
      fiscalPositionId: fiscalPositionId,
      companyId: companyId,
      teamId: teamId,
      signedBy: signedBy,
      signedOn: signedOn,
      commitmentDate: commitmentDate,
      showUpdatePricelist: showUpdatePricelist,
      createUid: createUid,
      writeUid: writeUid,
      writeDate: writeDate,
      incoterm: incoterm,
      pickingPolicy: pickingPolicy,
      warehouseId: warehouseId,
      procurementGroupId: procurementGroupId,
      effectiveDate: effectiveDate,
      saleOrderTemplateId: saleOrderTemplateId,
      placeorderdate: placeorderdate,
      verifydate: verifydate,
      customercontractid: customercontractid,
      region: region,
      province: province,
      salesdepartment: salesdepartment,
      deliverydate: deliverydate,
      iscp: iscp,
      deliveryproperties: deliveryproperties,
      remark: remark,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is SaleOrder &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          campaignId == other.campaignId &&
          sourceId == other.sourceId &&
          mediumId == other.mediumId &&
          accessToken == other.accessToken &&
          messageMainAttachmentId == other.messageMainAttachmentId &&
          name == other.name &&
          origin == other.origin &&
          clientOrderRef == other.clientOrderRef &&
          reference == other.reference &&
          state == other.state &&
          dateOrder == other.dateOrder &&
          validityDate == other.validityDate &&
          requireSignature == other.requireSignature &&
          requirePayment == other.requirePayment &&
          createDate == other.createDate &&
          user == other.user &&
          partnerId == other.partnerId &&
          partnerInvoiceId == other.partnerInvoiceId &&
          partnerShippingId == other.partnerShippingId &&
          pricelistId == other.pricelistId &&
          currencyId == other.currencyId &&
          analyticAccountId == other.analyticAccountId &&
          invoiceStatus == other.invoiceStatus &&
          note == other.note &&
          amountUntaxed == other.amountUntaxed &&
          amountTax == other.amountTax &&
          amountTotal == other.amountTotal &&
          currencyRate == other.currencyRate &&
          paymentTermId == other.paymentTermId &&
          fiscalPositionId == other.fiscalPositionId &&
          companyId == other.companyId &&
          teamId == other.teamId &&
          signedBy == other.signedBy &&
          signedOn == other.signedOn &&
          commitmentDate == other.commitmentDate &&
          showUpdatePricelist == other.showUpdatePricelist &&
          createUid == other.createUid &&
          writeUid == other.writeUid &&
          writeDate == other.writeDate &&
          incoterm == other.incoterm &&
          pickingPolicy == other.pickingPolicy &&
          warehouseId == other.warehouseId &&
          procurementGroupId == other.procurementGroupId &&
          effectiveDate == other.effectiveDate &&
          saleOrderTemplateId == other.saleOrderTemplateId &&
          placeorderdate == other.placeorderdate &&
          verifydate == other.verifydate &&
          customercontractid == other.customercontractid &&
          region == other.region &&
          province == other.province &&
          salesdepartment == other.salesdepartment &&
          deliverydate == other.deliverydate &&
          iscp == other.iscp &&
          deliveryproperties == other.deliveryproperties &&
          remark == other.remark);

  factory SaleOrder.allTrackFromMap(Map<String, dynamic> map) {
    return new SaleOrder(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      name: map['order_code'] != false
          ? map['order_code'].toString() as String?
          : "",
      dateOrder: map['order_date'] != false
          ? map['order_date'].toString() as String?
          : "",
      customercontractid: map['contract_id'] != false
          ? map['contract_id'].toString() as String?
          : "",
      customerName: map['customer_name'] != false
          ? map['customer_name'].toString() as String?
          : "",
      productName: map['product_name'] != false
          ? map['product_name'].toString() as String?
          : "",
      spec: map['product_style'] != false ? map['product_style'].toString() as String? : "",
      productQty: map['product_qty'] != false ? map['product_qty'].toString() as String? : "",
      clientOrderRef: map['client_order_ref'] != false
          ? map['client_order_ref'].toString() as String?
          : "",
      reference: map['reference'] != false
          ? map['reference'].toString() as String?
          : "",
      state: map['state'] != false ? map['state'].toString() as String? : "",
      unit: map['uom_id'] != false
          ? map['uom_id'].toString() as String?
          : "",
      autoid: map['autoid'] != false
          ? map['autoid'].toString() as String?
          : "",
    );
  }

  factory SaleOrder.fromMap(Map<String, dynamic> map) {
    return new SaleOrder(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      campaignId: map['campaign_id'] != false
          ? map['campaign_id'].toString() as String?
          : "",
      sourceId: map['source_id'] != false
          ? map['source_id'].toString() as String?
          : "",
      mediumId: map['medium_id'] != false
          ? map['medium_id'].toString() as String?
          : "",
      accessToken: map['access_token'] != false
          ? map['access_token'].toString() as String?
          : "",
      messageMainAttachmentId: map['message_main_attachment_id'] != false
          ? map['message_main_attachment_id'].toString() as String?
          : "",
      name: map['name'] != false ? map['name'].toString() as String? : "",
      origin: map['origin'] != false ? map['origin'].toString() as String? : "",
      clientOrderRef: map['client_order_ref'] != false
          ? map['client_order_ref'].toString() as String?
          : "",
      reference: map['reference'] != false
          ? map['reference'].toString() as String?
          : "",
      state: map['state'] != false ? map['state'].toString() as String? : "",
      dateOrder: map['date_order'] != false
          ? map['date_order'].toString() as String?
          : "",
      validityDate: map['validity_date'] != false
          ? map['validity_date'].toString() as String?
          : "",
      requireSignature: map['require_signature'] != false
          ? map['require_signature'].toString() as String?
          : "",
      requirePayment: map['require_payment'] != false
          ? map['require_payment'].toString() as String?
          : "",
      createDate: map['create_date'] != false
          ? map['create_date'].toString() as String?
          : "",
      user: map['user_id'] != false ? map['user_id'].toString() as String? : "",
      userName: map['user_id'] != false
          ? map['user_id'][1].toString() as String?
          : "",
      partnerId: map['partner_id'] != false
          ? map['partner_id'].toString() as String?
          : "",
      partnerName: map['partner_id'] != false
          ? map['partner_id'][1].toString() as String?
          : "",
      partnerInvoiceId: map['partner_invoice_id'] != false
          ? map['partner_invoice_id'].toString() as String?
          : "",
      partnerShippingId: map['partner_shipping_id'] != false
          ? map['partner_shipping_id'].toString() as String?
          : "",
      pricelistId: map['pricelist_id'] != false
          ? map['pricelist_id'].toString() as String?
          : "",
      currencyId: map['currency_id'] != false
          ? map['currency_id'].toString() as String?
          : "",
      analyticAccountId: map['analytic_account_id'] != false
          ? map['analytic_account_id'].toString() as String?
          : "",
      invoiceStatus: map['invoice_status'] != false
          ? map['invoice_status'].toString() as String?
          : "",
      note: map['note'] != false ? map['note'].toString() as String? : "",
      amountUntaxed: map['amount_untaxed'] != false
          ? map['amount_untaxed'].toString() as String?
          : "",
      amountTax: map['amount_tax'] != false
          ? map['amount_tax'].toString() as String?
          : "",
      amountTotal: map['amount_total'] != false
          ? map['amount_total'].toString() as String?
          : "",
      currencyRate: map['currency_rate'] != false
          ? map['currency_rate'].toString() as String?
          : "",
      paymentTermId: map['payment_term_id'] != false
          ? map['payment_term_id'].toString() as String?
          : "",
      fiscalPositionId: map['fiscal_position_id'] != false
          ? map['fiscal_position_id'].toString() as String?
          : "",
      companyId: map['company_id'] != false
          ? map['company_id'].toString() as String?
          : "",
      companyName: map['company_id'] != false
          ? map['company_id'][1].toString() as String?
          : "",
      teamId:
      map['team_id'] != false ? map['team_id'].toString() as String? : "",
      signedBy: map['signed_by'] != false
          ? map['signed_by'].toString() as String?
          : "",
      signedOn: map['signed_on'] != false
          ? map['signed_on'].toString() as String?
          : "",
      commitmentDate: map['commitment_date'] != false
          ? map['commitment_date'].toString() as String?
          : "",
      showUpdatePricelist: map['show_update_pricelist'] != false
          ? map['show_update_pricelist'].toString() as String?
          : "",
      createUid: map['create_uid'] != false
          ? map['create_uid'].toString() as String?
          : "",
      writeUid: map['write_uid'] != false
          ? map['write_uid'].toString() as String?
          : "",
      writeDate: map['write_date'] != false
          ? map['write_date'].toString() as String?
          : "",
      incoterm:
      map['incoterm'] != false ? map['incoterm'].toString() as String? : "",
      pickingPolicy: map['picking_policy'] != false
          ? map['picking_policy'].toString() as String?
          : "",
      warehouseId: map['warehouse_id'] != false
          ? map['warehouse_id'].toString() as String?
          : "",
      procurementGroupId: map['procurement_group_id'] != false
          ? map['procurement_group_id'].toString() as String?
          : "",
      effectiveDate: map['effective_date'] != false
          ? map['effective_date'].toString() as String?
          : "",
      saleOrderTemplateId: map['sale_order_template_id'] != false
          ? map['sale_order_template_id'].toString() as String?
          : "",
      placeorderdate: map['placeorderdate'] != false
          ? Utils.getDate(date: map['placeorderdate'].toString())
          : "",
      verifydate: map['verifydate'] != false
          ? map['verifydate'].toString() as String?
          : "",
      customercontractid: map['customercontractid'] != false
          ? map['customercontractid'].toString() as String?
          : "",
      region: map['region'] != false ? map['region'].toString() as String? : "",
      province:
      map['province'] != false ? map['province'].toString() as String? : "",
      salesdepartment: map['salesdepartment'] != false
          ? map['salesdepartment'].toString() as String?
          : "",
      deliverydate: map['deliverydate'] != false
          ? Utils.getDate(date: map['deliverydate'].toString())
          : "",
      iscp: map['iscp'] != false ? map['iscp'].toString() as String? : "",
      deliveryproperties: map['deliveryproperties'] != false
          ? map['deliveryproperties'].toString() as String?
          : "",
      remark: map['remark'] != false ? map['remark'].toString() as String? : "",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'campaignId': this.campaignId,
      'sourceId': this.sourceId,
      'mediumId': this.mediumId,
      'accessToken': this.accessToken,
      'messageMainAttachmentId': this.messageMainAttachmentId,
      'name': this.name,
      'origin': this.origin,
      'clientOrderRef': this.clientOrderRef,
      'reference': this.reference,
      'state': this.state,
      'dateOrder': this.dateOrder,
      'validityDate': this.validityDate,
      'requireSignature': this.requireSignature,
      'requirePayment': this.requirePayment,
      'createDate': this.createDate,
      'user': this.user,
      'partnerId': this.partnerId,
      'partnerInvoiceId': this.partnerInvoiceId,
      'partnerShippingId': this.partnerShippingId,
      'pricelistId': this.pricelistId,
      'currencyId': this.currencyId,
      'analyticAccountId': this.analyticAccountId,
      'invoiceStatus': this.invoiceStatus,
      'note': this.note,
      'amountUntaxed': this.amountUntaxed,
      'amountTax': this.amountTax,
      'amountTotal': this.amountTotal,
      'currencyRate': this.currencyRate,
      'paymentTermId': this.paymentTermId,
      'fiscalPositionId': this.fiscalPositionId,
      'companyId': this.companyId,
      'teamId': this.teamId,
      'signedBy': this.signedBy,
      'signedOn': this.signedOn,
      'commitmentDate': this.commitmentDate,
      'showUpdatePricelist': this.showUpdatePricelist,
      'createUid': this.createUid,
      'writeUid': this.writeUid,
      'writeDate': this.writeDate,
      'incoterm': this.incoterm,
      'pickingPolicy': this.pickingPolicy,
      'warehouseId': this.warehouseId,
      'procurementGroupId': this.procurementGroupId,
      'effectiveDate': this.effectiveDate,
      'saleOrderTemplateId': this.saleOrderTemplateId,
      'placeorderdate': this.placeorderdate,
      'verifydate': this.verifydate,
      'customercontractid': this.customercontractid,
      'region': this.region,
      'province': this.province,
      'salesdepartment': this.salesdepartment,
      'deliverydate': this.deliverydate,
      'iscp': this.iscp,
      'deliveryproperties': this.deliveryproperties,
      'remark': this.remark,
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.name != null && this.name != '')
        ['name', 'like', '%${this.name}%'],
      if (this.customercontractid != null && this.customercontractid != '')
        ['customercontractid', 'like', '%${this.customercontractid}%'],
      if (this.placeorderdateStart != null && this.placeorderdateStart != '')
        [
          'placeorderdate',
          '>=',
          this.placeorderdateStart! + " 00:00:00"
        ],
      if (this.placeorderdateEnd != null && this.placeorderdateEnd != '')
        [
          'placeorderdate',
          '<=',
          this.placeorderdateEnd! + " 23:59:59"
        ],
    ] as List;
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'campaign_id': this.campaignId,
      'source_id': this.sourceId,
      'medium_id': this.mediumId,
      'access_token': this.accessToken,
      'message_main_attachment_id': this.messageMainAttachmentId,
      'name': this.name,
      'origin': this.origin,
      'client_order_ref': this.clientOrderRef,
      'reference': this.reference,
      'state': this.state,
      'date_order': this.dateOrder,
      'validity_date': this.validityDate,
      'require_signature': this.requireSignature,
      'require_payment': this.requirePayment,
      'create_date': this.createDate,
      'user_id': this.user,
      'partner_id': this.partnerId,
      'partner_invoice_id': this.partnerInvoiceId,
      'partner_shipping_id': this.partnerShippingId,
      'pricelist_id': this.pricelistId,
      'currency_id': this.currencyId,
      'analytic_account_id': this.analyticAccountId,
      'invoice_status': this.invoiceStatus,
      'note': this.note,
      'amount_untaxed': this.amountUntaxed,
      'amount_tax': this.amountTax,
      'amount_total': this.amountTotal,
      'currency_rate': this.currencyRate,
      'payment_term_id': this.paymentTermId,
      'fiscal_position_id': this.fiscalPositionId,
      'company_id': this.companyId,
      'team_id': this.teamId,
      'signed_by': this.signedBy,
      'signed_on': this.signedOn,
      'commitment_date': this.commitmentDate,
      'show_update_pricelist': this.showUpdatePricelist,
      'create_uid': this.createUid,
      'write_uid': this.writeUid,
      'write_date': this.writeDate,
      'incoterm': this.incoterm,
      'picking_policy': this.pickingPolicy,
      'warehouse_id': this.warehouseId,
      'procurement_group_id': this.procurementGroupId,
      'effective_date': this.effectiveDate,
      'sale_order_template_id': this.saleOrderTemplateId,
      'placeorderdate': this.placeorderdate,
      'verifydate': this.verifydate,
      'customercontractid': this.customercontractid,
      'region': this.region,
      'province': this.province,
      'salesdepartment': this.salesdepartment,
      'deliverydate': this.deliverydate,
      'iscp': this.iscp,
      'deliveryproperties': this.deliveryproperties,
      'remark': this.remark,
    } as Map<String, dynamic>;
  }

//</editor-fold>

}
